package cn.edu.sdju.fengguoyu.logger;

import cn.edu.sdju.fengguoyu.ahoedgemonitor.App;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Logger {
    private String label = "";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public Logger(Class<?> cls) {
        this.label = cls.getName();
    }

    public void  log(String info) {
        String formattedDateTime = LocalDateTime.now().format(formatter);
        String output = formattedDateTime +
                " | " +
                label +
                ": "  +
                info  +
                "\n";
        if (App.logTextArea != null)
            App.logTextArea.appendText(output);
        else {
            System.out.println(output);
        }
    }

}
